/**
 * 公告js
 */
layui.use(['form','layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  //墨绿主题
  laydate.render({
    elem: '#aborttime'
    ,theme: 'molv'
    ,trigger: 'click'
  });
  
  form.on('select(fsdx)',function(data){
	  var op=data.value;
	  if(op=="班级"){
		  $("#banji").css("display","block");
		  $("#xuesheng").css("display","none");
	  }else{
		  $("#xuesheng").css("display","none");
		  $("#banji").css("display","none");
	  }
  })
  $.ajax({
	  url:"getClazzAll",
		type:"get",
		success:function(data){
			if(data){
				var jieguo=data.data;
				for (var i = 0; i < jieguo.length; i++) {
				    $("#clazz_id").append("<option value="+jieguo[i].clazz_id+">"+jieguo[i].clazz_name+"</option>");
				}
				form.render();
			}
		}
  });
});

$(function(){
	$('#addbotton').click(function(){
		var index=[false,false];
		var notice_title=$("input[name='notice_title']").val();
		var notice_content=$("#notice_content").val();
		if(notice_title!=null&&notice_title!=""){
			index[0]=true;
		}
		if(notice_content!=null&&notice_content!=''){
			index[1]=true;	
		}
		if(index[0]&&index[1]){
			$.ajax({
				  url:"noticeadd",
					type:"post",
					data:{
						notice_title:notice_title,
						notice_content:notice_content,
						notice_jibie:$("#notice_jibie option:checked").val(),
						aborttime:$("#aborttime").val(),
						clazz:$("#clazz_id option:checked").val()
					},
					success:function(data){
						if(data){
							location.href="noticelist";
						}
					}
			  });
		}else{
			alert("没有通过验证")
		}
	});
	
});